package cn.vihub.controller;

import cn.vihub.handler.MyRuntimeException;
import cn.vihub.param.ShopGoodsParam;
import cn.vihub.param.ShopOrderParam;
import cn.vihub.service.ShopOrderService;
import cn.vihub.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 秋晚
 * @Date: 2025/8/7 20:24
 * @Description:
 **/
@RestController
@RequestMapping("shop-store/ShopOrder")
public class ShopOrderController {

    @Autowired
    ShopOrderService shopOrderService;

    /**
     * @author: 秋晚
     * @description:添加一条订单记录
     * @params: [java.lang.Integer, cn.vihub.param.ShopOrderParam]
     * @return: cn.vihub.utils.Result<java.lang.Boolean>
     * @date: 2025/8/7 20:58
     */
    @PostMapping("add")
    public Result<Boolean> add(@RequestHeader("X-Member-Id")Integer memberId, @RequestBody ShopOrderParam shopOrderParam){
        //给订单赋所属用户id值
        shopOrderParam.setMemberId(memberId);
        //判断订单商品集合不能为空
        if(shopOrderParam.getOrderGoodsParamList()==null){
            return Result.error("商品集合不能为空");
        }
        return Result.success(shopOrderService.add(shopOrderParam));
    }



    /**
     * @author: 秋晚
     * @description:秒杀商品
     * @params: [java.lang.Integer, cn.vihub.param.ShopOrderParam]
     * @return: cn.vihub.utils.Result<java.lang.Boolean>
     * @date: 2025/8/8 13:25
     */
    @PostMapping ("addOne")
    public Result<Boolean> addOne(@RequestHeader("X-Member-Id")Integer memberId, @RequestBody ShopOrderParam shopOrderParam){
        //给订单赋所属用户id值
        shopOrderParam.setMemberId(memberId);
        //判断订单商品集合不能为空
        if(shopOrderParam.getOrderGoodsParamList()==null){
            return Result.error("商品集合不能为空");
        }
        return Result.success(shopOrderService.addOne(shopOrderParam));
    }
}
